home *** CD-ROM | disk | FTP | other *** search
- /*-----------------------------------------------------------------------
- AUTHOR : Greg Scratchley
- Program Name : SHOWIT
- Version Num : v1.1 released.
- Program Files: Showit.c
- Showit.exe
- Program Desc.: Showit is designed to display a text file given the name
- and path of the textfile to be viewed. The program
- allows scrolling forward and backward through the doc.
- at the users discretion. Ansi.sys must be loaded for this
- program to work correctly.
-
- This program is cardware. If you like it and think it merits a pat on
- my widdle back, send me a postcard!
-
- G Scratchley
- 65 Glamorgan Drive
- Sherwood Park Alberta
- Canada
-
- T8A 2Y5
-
- -----------------------------------------------------------------------*/
-
-
-
- #include <stdio.h>
- #include <string.h>
- #define MAX 200
-
-
- int readfile (char filen[]);
-
- /**************************************************************************
-
- Function Name: main
- Parameters : int argv, char argv
- Return Value : error code 0 to dos
- Function : accepts command line entry and acts as command shell for all
- subroutines
-
- **************************************************************************/
-
- int main(int argc, char *argv[])
- {
- char filen [80];
- int errorlevel=0;
- char errorstring[75];
- int frcount=0;
- if (argc!=2) /* if command line strings not = 2 */
- {
- printf("\n\nUsage \33[40;33;1mC:\SHOWIT a:\\test.txt\33[40;37;0m\n\n");
- printf("\nIf the above line looked distorted, please include the following in config.sys\n\n");
- printf("----------> device=c:\\dos\\ansi.sys \n\n\n");
- return 0;
- }
- sscanf(argv[1],"%s",&filen); /* scan cmdlin string 2 into filen */
- errorlevel=readfile(filen); /* retrieve errorlevel from readfile */
- /* passing the filename from cmdlin */
- fflush(stdin);
-
- printf("\n\n\n\33[40;31;1mError Log\33[40;37;0m > \33[40;33;1m");
- if (errorlevel==0)
- {
- printf("No errors - user exited at end of document\n\n");
- }
- if (errorlevel==1)
- {
- printf("Error retrieving file - Check the Path\n\n");
- }
- if (errorlevel==2)
- {
- printf("No errors - user exited before end of document\n\n");
- }
- printf("\33[37;44;1m");
- printf("\n");
- printf("\xC9");
- for (frcount=0;frcount<=77;frcount++)
- printf("\xcd");
- printf("\xbb");
- printf("\xba \xba");
- printf("\xba Thanks for using \33[44;33;1mSoftware from Scratch\33[37;44;0m\33[37;44;1m! If you find this program useful \xba");
- printf("\xba please drop a postcard to a college student in distress... \xba");
- printf("\xba \xba");
- printf("\xba \33[31;44;1mSoftware From Scratch\33[44;37;1m \xba");
- printf("\xba \33[31;44;1m65 Glamorgan Drive\33[44;37;1m \xba");
- printf("\xba \33[31;44;1mSherwood Park, Alberta\33[44;37;1m \xba");
- printf("\xba \33[31;44;1mT8A 2Y5\33[44;37;1m \xba");
- printf("\xba \xba");
- printf("\xba P.S. Thanks L.P! \xba");
- printf("\xC8");
- for (frcount=0;frcount<=77;frcount++)
- printf("\xcd");
- printf("\xBC");
- printf("\33[40;37;0m");
- fflush(stdin);
- return 0;
- }
-
- /**************************************************************************
- Function Name:readfile
- Parameters :char filen (filename from main)
- Return Value :integer for errorlevel
- Function :reads the file and displays it one screen at a time, forward
- and backward at the users discretion.
-
- **************************************************************************/
-
-
-
- int readfile (char filen[])
- {
- int loopcount=0;
- int pagecount=1;
- FILE *infile; /* associates pointer to infile from */
- /* FILE stream */
- fpos_t current[MAX]; /* initializes pointer current[] for */
- /* file position data */
- int cntchar=0; /* Inits for runtime var's */
- int lincount=0;
- int count=0;
- char charstr;
- int doneptr=0;
- int errorlevel;
- char readdir;
- printf("\33[2J");
- infile=fopen(filen,"r"); /* specifies value of infile as */
- /* file filen */
- fgetpos(infile,¤t[count]); /* If file not located show error */
- if (infile==NULL)
- {
- printf("\n\n\n FILE NOT FOUND! \n\n ");
- errorlevel=1;
- return (errorlevel);
- }
- do /* For each char returned check for */
- {
- charstr = fgetc(infile);
- if (charstr=='\n') /* Check for CR */
- {
- lincount++;
- cntchar=0;
- }
- if (cntchar==80) /* Check to see if line is full */
- {
- lincount++;
- cntchar=0;
- }
- if (lincount==23) /* check to see if page is full */
- {
- cntchar=0;
- lincount=0;
- printf("\n\33[34;40;1mCurrent File: \33[31;40;1m %s \33[40;37;0m",filen);
- printf("\n\33[37;44;1m\xba Software from Scratch \xba FWD <CR> \xba REV <-> \xba QUIT <q> \xba Page %d \xba Choice?:\33[40;37;0m",pagecount);
- fflush(stdin);
- readdir=getchar();
- printf("\33[2J");
- switch (readdir) /* Switch for user input */
- {
- case '\n': /* if enter is pressed*/
- {
- count++; /* inc count and store new page ptr */
- pagecount++;
- fgetpos(infile,¤t[count]);
- cntchar=0;
- break;
- }
- case '-' : /* If minus sign is pressed */
- {
- if (count==0) /* dec counter (if not zero already) */
- {
- count++; /* & set ptr to previous value stored*/
- pagecount++;
- }
- count--;
- pagecount--;
- fsetpos(infile,¤t[count]);
- cntchar=0;
- break;
- }
- case 'q':
- { /* If Quit, append error2 and */
- errorlevel=2; /* return to main */
- return errorlevel;
- }
- case 'Q':
- {
- errorlevel=2;
- return errorlevel;
- }
- default:
- {
- break;
- }
- }
- }
- else
- {
- printf("%c",charstr); /* Print the char to screen */
- cntchar++; /* increment the counter */
- }
- if (feof(infile)) /* if the EOF has been reached */
- {
- for (loopcount=(21-lincount);loopcount>=0;loopcount--)
- printf("\n");
- printf("\n\33[34;40;1mCurrent File: \33[31;40;1m %s \33[40;37;0m\n",filen);
- printf("\33[37;44;1m\xba Software from Scratch \xba FWD <CR> \xba REV <-> \xba QUIT <q> \xba Page %d <EOF> \xba ?:\33[40;37;0m",pagecount);
- fflush(stdin);
- readdir=getchar(); /* get in choice */
- fflush(stdin);
- printf("\33[2J");
- switch (readdir)
- {
- case '-':
- {
- if (pagecount==1)
- {
- count++;
- pagecount++;
- }
- count--;
- pagecount--;
- fsetpos(infile,¤t[count]);
- cntchar=0;
- lincount=0;
- break;
- }
- case 'Q':
- {
- doneptr=1;
- break;
- }
- case 'q':
- {
- doneptr=1;
- break;
- }
-
- default :
- {
- fsetpos(infile,¤t[count]); /* If enter or key+enter */
- cntchar=0; /* is pressed, redraw */
- lincount=0;
- break;
- }
- }
- }
- }
- while (doneptr==0); /* when finished.....*/
- fclose(infile); /*close the infile (give it a shake)*/
- fflush(stdin); /*don't forget to flush */
- errorlevel=0; /*assign error 0 */
- return (errorlevel) ; /* return the errorlevel to main */
- }